<template>
  <div>
    <el-dropdown trigger="click" @command="changelanguage">
      <div>
        <svg-icon style="color: #fff; font-size: 20px" icon-class="language" />
      </div>
      <el-dropdown-menu slot="dropdown">
        <el-dropdown-item command="zh" :disabled="'zh' === $i18n.locale">
          中文
        </el-dropdown-item>
        <el-dropdown-item command="en" :disabled="'en' === $i18n.locale">
          en
        </el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
  </div>
</template>

<script>
import cookie from 'js-cookie'
export default {
  name: 'Language',
  methods: {
    changelanguage (lang) {
      const expires = 3
      cookie.set('language', lang, { expires })
      this.$i18n.locale = lang
      this.$message.success('切换语言成功')
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
